using System;
using System.Collections.Generic;
using System.Text;

namespace Lib.Utilities
{
    public class CommonUtility
    {
        public static string RemoveStrHtmlTags(string inputString, string splitter)
        {
            return RemoveStrHtmlTags(inputString, splitter, false);
        }

        public static string RemoveStrHtmlTags(string inputString, string splitter, bool removeSigns)
        {
            string strInput = inputString.Trim();
            if (strInput != "") strInput = System.Text.RegularExpressions.Regex.Replace(strInput, @"<(.|\n)*?>", (string.IsNullOrEmpty(splitter)) ? string.Empty : splitter);
            else return null;
            if (removeSigns)
            {
                strInput = System.Text.RegularExpressions.Regex.Replace(strInput, @"[\W_,.\t]", (string.IsNullOrEmpty(splitter)) ? string.Empty : splitter);
            }
            char tab = '\u0009';
            strInput = strInput.Replace(tab.ToString(), " ");

            strInput = strInput.Replace(Environment.NewLine, "");

            while (strInput.IndexOf("  ") > 0)
                strInput = strInput.Replace("  ", " ");
            while(strInput.IndexOf(Environment.NewLine)>0)
                strInput = strInput.Replace(Environment.NewLine, "");
            while (strInput.IndexOf(splitter + " ") > 0 || strInput.IndexOf(" "+splitter) > 0)
                strInput = strInput.Replace(splitter + " ", splitter).Replace(" " + splitter, splitter);
            while (!string.IsNullOrEmpty(splitter) && strInput.IndexOf(splitter + splitter) >= 0)
                strInput = strInput.Replace(splitter + splitter, splitter);
            
            return strInput;
        }
    }
}
